﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace UnitTestSample2
{
    class Program
    {
        static void Main(string[] args)
        {
            var asms = new List<Assembly>();
            var dinfo = new DirectoryInfo(@".");
            var files = dinfo.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
            for (var i = 0; i < files.Length; i++)
                asms.Add(Assembly.LoadFrom(files[i].FullName));
            TestRunner.Current.LoadAssembly(asms);

            TestRunner.Current.TestStarting += (sender, e) => 
            {
                Console.WriteLine("**** テスト開始 ****************************");
            };

            var okCount = 0;
            var ngCount = 0;

            TestRunner.Current.TestProgress += (sender, e) =>
            {
                Console.WriteLine("・{0} => 結果:{1}", e.Name, e.Result);
                if (!e.Result)
                {
                    Console.WriteLine("    {0}", e.Error.Message);
                    Console.WriteLine("    {0}", e.Error.StackTrace);
                }

                if (e.Result)
                    okCount++;
                else
                    ngCount++;
            };

            TestRunner.Current.TestFinished += (sender, e) =>
            {
                Console.WriteLine("**** テスト終了 ****************************");
                Console.WriteLine("    全体:{0}、OK:{1}、NG:{2}", okCount+ngCount, okCount, ngCount);
            };

            TestRunner.Current.Run();

            Console.ReadLine();
        }
    }
}
